#include"spritefactory.h"
spritefactory::spritefactory() {
	//this->createSprite = &spritefactory::spriteFactoryCreateSprite;//获取成员函数的地址，并将其存储在成员函数指针中
	unsigned int h;
	//block_1x1
	h = DJBHash("block_1x1") % LENGTH_OF_CREATE_SPRITE_FUNC_ARR;
	if (this->createSpriteFuncArr[h] != NULL) {
		hashCollision();
		return;
	}
	this->createSpriteFuncArr[h] = createBlock_1x1;
	//softblock_1x1
	h = DJBHash("softblock_1x1") % LENGTH_OF_CREATE_SPRITE_FUNC_ARR;
	if (this->createSpriteFuncArr[h] != NULL) {
		hashCollision();
		return;
	}
	this->createSpriteFuncArr[h] = createSoftBlock_1x1;
	//enemy1_1x1
	h = DJBHash("enemy1_1x1") % LENGTH_OF_CREATE_SPRITE_FUNC_ARR;
	if (this->createSpriteFuncArr[h] != NULL) {
		hashCollision();
		return;
	}
	this->createSpriteFuncArr[h] = createEnemy1_1x1;

	//tube_2x2
	h = DJBHash("tube_2x2") % LENGTH_OF_CREATE_SPRITE_FUNC_ARR;
	if (this->createSpriteFuncArr[h] != NULL) {
		hashCollision();
		return;
	}
	this->createSpriteFuncArr[h] = createTube_2x2;
}
sprite* spritefactory::spriteFactoryCreateSprite(const char* spriteName) {
	unsigned int h;
	h = DJBHash(spriteName) % LENGTH_OF_CREATE_SPRITE_FUNC_ARR;
	TYPE_CREATE_SPRITE_FUNC pFunc = this->createSpriteFuncArr[h];
	if (pFunc == NULL) {
		return NULL;
	}
	class sprite* pSprite = pFunc();
	return pSprite;
}